home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / text / StyledEditorKit$StyledTextAction.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  1.9 KB  |  58 lines

  1. package javax.swing.text;
  2.  
  3. import java.awt.event.ActionEvent;
  4. import javax.swing.JEditorPane;
  5.  
  6. public abstract class StyledEditorKit$StyledTextAction extends TextAction {
  7.    public StyledEditorKit$StyledTextAction(String var1) {
  8.       super(var1);
  9.    }
  10.  
  11.    protected final JEditorPane getEditor(ActionEvent var1) {
  12.       JTextComponent var2 = ((TextAction)this).getTextComponent(var1);
  13.       return var2 instanceof JEditorPane ? (JEditorPane)var2 : null;
  14.    }
  15.  
  16.    protected final StyledDocument getStyledDocument(JEditorPane var1) {
  17.       Document var2 = ((JTextComponent)var1).getDocument();
  18.       if (var2 instanceof StyledDocument) {
  19.          return (StyledDocument)var2;
  20.       } else {
  21.          throw new IllegalArgumentException("document must be StyledDocument");
  22.       }
  23.    }
  24.  
  25.    protected final StyledEditorKit getStyledEditorKit(JEditorPane var1) {
  26.       EditorKit var2 = var1.getEditorKit();
  27.       if (var2 instanceof StyledEditorKit) {
  28.          return (StyledEditorKit)var2;
  29.       } else {
  30.          throw new IllegalArgumentException("EditorKit must be StyledEditorKit");
  31.       }
  32.    }
  33.  
  34.    protected final void setCharacterAttributes(JEditorPane var1, AttributeSet var2, boolean var3) {
  35.       int var4 = ((JTextComponent)var1).getSelectionStart();
  36.       int var5 = ((JTextComponent)var1).getSelectionEnd();
  37.       if (var4 != var5) {
  38.          StyledDocument var6 = this.getStyledDocument(var1);
  39.          var6.setCharacterAttributes(var4, var5 - var4, var2, var3);
  40.       }
  41.  
  42.       StyledEditorKit var8 = this.getStyledEditorKit(var1);
  43.       MutableAttributeSet var7 = var8.getInputAttributes();
  44.       if (var3) {
  45.          var7.removeAttributes(var7);
  46.       }
  47.  
  48.       var7.addAttributes(var2);
  49.    }
  50.  
  51.    protected final void setParagraphAttributes(JEditorPane var1, AttributeSet var2, boolean var3) {
  52.       int var4 = ((JTextComponent)var1).getSelectionStart();
  53.       int var5 = ((JTextComponent)var1).getSelectionEnd();
  54.       StyledDocument var6 = this.getStyledDocument(var1);
  55.       var6.setParagraphAttributes(var4, var5 - var4, var2, var3);
  56.    }
  57. }
  58.